
package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.member.model.Member;
import com.eling.elcms.ordermanager.model.ServicePoint;
import com.eling.elcms.privilege.service.impl.CommonPrivilegeCriteriaEnhancer;
import com.eling.elcms.system.model.CommonUser;
import com.eling.elcms.travel.model.ProductRuleDetail.Unit;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;
/**
 * 合同签约
 * @author linjizeng
 * 
 */
@Entity
@Table(name = "travel_travelcontract")
@Indexed
@CriteriaEnhancers(criteriaEnhancers = {
		@CriteriaEnhancer(impl = OrderCriteriaEnhancer.class, parameter = "signUpDate:desc"),
		@CriteriaEnhancer(impl = CommonPrivilegeCriteriaEnhancer.class, parameter = "servicepoint:servicePoint")})
public class TravelContract  extends BaseModel{

	private static final long serialVersionUID = 414622997336008264L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	@In
	private Long pkTravelContract;
	
	/**所属服务点*/
	@ManyToOne(fetch = FetchType.LAZY)
	@In
	@JoinColumn(name = "pkServicePoint")
    @IndexedEmbedded(depth = 1)
	private ServicePoint servicePoint;
	
	/** 会员*/
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkMember")
	@IndexedEmbedded(depth = 1)
	private Member member;
	
	/** 产品*/
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkProductRule")
	@IndexedEmbedded(depth = 1)
	private ProductRule productRule;
	
	/** 产品类型 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkProductType")
	@IndexedEmbedded(depth = 1)
	private ProductType productType;
	
	/** 产品批次 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkProductBatch")
	@IndexedEmbedded(depth = 1)
	private ProductBatch productBatch;
	
	/** 合同号*/
	@Column(unique = true)
	@Field
	private String contactNo;
	
	/** 购买份数*/
	@Column
	@Field
	private Integer number;
	
	/** 金额*/
	@Column
	@Field
	private Double price;
	
	/** 余额*/
	@Column
	@Field
	private Double balance;
	
	//TODO:两个余额合并
	/** 居住期限余额(时间)*/
	@Column
	@Field
	private Double balTime;
	
	
	/** 期限单位 */
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private Unit unit;
		
	
	/** 会员证号 */
	@Column
	@Field
	private String memberCertificates;
	
	/** 签约日期 */
	@Column
	@Field
	@Between
	private Date signUpDate;
	
	/** 开始日期 */
	@Column
	@Field
	@Between
	private Date startDate;
	
	/** 结束日期 */
	@Column
	@Field
	@Between
	private Date endDate;
	
	/** 操作人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "operator")
	@IndexedEmbedded(depth = 1)
	private CommonUser operator;
	
	/** 描述 */
	@Column(length = 1023)
	@Field
	private String description;
	
	/** 图片上传路径 */
	@Column(length = 1023)
	@Field
	private String picturePath;
	
	/**单价（只针对居住期限的）*/
	@Column
	@Field
	private Double unitPrice;
	
	/** 签约状态*/
	@Enumerated(EnumType.STRING)
	@In	
	@FieldBridge(impl = EnumBridge.class)
	private Status status;
	
	@JsonSerialize(using = EnumSerializer.class)
	public static enum Status {
		Initial("初始"),
		Valid("有效"), 
		Finish("终止");

		private String display;
		Status(String display) {
			this.display = display;
		}
		public String getDisplay() {
			return display;
		}
	}
	
	/** 签约回访状态*/
	@Enumerated(EnumType.STRING)
	@In	
	@FieldBridge(impl = EnumBridge.class)
	private VisitStatus visitStatus;
	
	@JsonSerialize(using = EnumSerializer.class)
	public static enum VisitStatus {
		Visit("已回访"),
		NoVisit("未回访");

		private String display;
		VisitStatus(String display) {
			this.display = display;
		}
		public String getDisplay() {
			return display;
		}
	}
	
	@Version
	private Integer version;


	public Double getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(Double unitPrice) {
		this.unitPrice = unitPrice;
	}

	public Long getPkTravelContract() {
		return pkTravelContract;
	}

	public void setPkTravelContract(Long pkTravelContract) {
		this.pkTravelContract = pkTravelContract;
	}

	public ServicePoint getServicePoint() {
		return servicePoint;
	}

	public void setServicePoint(ServicePoint servicePoint) {
		this.servicePoint = servicePoint;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public ProductRule getProductRule() {
		return productRule;
	}

	public void setProductRule(ProductRule productRule) {
		this.productRule = productRule;
	}

	public ProductBatch getProductBatch() {
		return productBatch;
	}

	public void setProductBatch(ProductBatch productBatch) {
		this.productBatch = productBatch;
	}

	public ProductType getProductType() {
		return productType;
	}

	public void setProductType(ProductType productType) {
		this.productType = productType;
	}

	public String getContactNo() {
		return contactNo;
	}

	public void setContactNo(String contactNo) {
		this.contactNo = contactNo;
	}

	public Integer getNumber() {
		return number;
	}

	public void setNumber(Integer number) {
		this.number = number;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public String getMemberCertificates() {
		return memberCertificates;
	}

	public void setMemberCertificates(String memberCertificates) {
		this.memberCertificates = memberCertificates;
	}

	public Date getSignUpDate() {
		return signUpDate;
	}

	public void setSignUpDate(Date signUpDate) {
		this.signUpDate = signUpDate;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public CommonUser getOperator() {
		return operator;
	}

	public void setOperator(CommonUser operator) {
		this.operator = operator;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getPicturePath() {
		return picturePath;
	}

	public void setPicturePath(String picturePath) {
		this.picturePath = picturePath;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Double getBalance() {
		return balance;
	}

	public void setBalance(Double balance) {
		this.balance = balance;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public VisitStatus getVisitStatus() {
		return visitStatus;
	}

	public void setVisitStatus(VisitStatus visitStatus) {
		this.visitStatus = visitStatus;
	}

	public Double getBalTime() {
		return balTime;
	}

	public void setBalTime(Double balTime) {
		this.balTime = balTime;
	}

	public Unit getUnit() {
		return unit;
	}

	public void setUnit(Unit unit) {
		this.unit = unit;
	}
	
}
